<template>
	<view>
		<!-- 笔录签字 -->
		<sign-view v-if="saveUrl" @save="save" :bgIndex="1"></sign-view>
		<sign-view v-if="saveUrl2" @save="bilu" :bgIndex="2"></sign-view>
		<transcript-view style="position: fixed !important;top: 0 !important;bottom: 0 !important;right: 0 !important;left: 0 !important;z-index: 9999 !important;" v-if="isTranscript" :transcriptList="transcriptList" @submit="submit"></transcript-view>
		<!-- 权力义务告知书签字 -->
		<sign-view v-if="isObligation2" @save="save2" :bgIndex="1"></sign-view>
		<!-- 行政处罚告知书描边 -->
		<sign-view v-if="isAdministrative2" @save="bilu2" :bgIndex="2"></sign-view>
		<!-- 行政处罚告知书签字 -->
		<sign-view v-if="isAdministrative3" @save="save3" :bgIndex="1"></sign-view>
		<!-- 听证告知书描边 -->
		<sign-view v-if="isheadringNotice2" @save="stroke" :bgIndex="2"></sign-view>
		<!-- 听证告知书签字 -->
		<sign-view v-if="isheadringNotice3" @save="hearingsign" :bgIndex="1"></sign-view>
		<!-- 权力义务告知书 -->
		<obligation-inform v-if="isObligation" class="inform-position" :obligationObj="obligationObj" @submit="obligationFun"></obligation-inform>
		<!-- 行政处罚告知书 -->
		<administrative-penalties v-if="isAdministrative" :administrativeObj="administrativeObj" @submit="administrativeFun"></administrative-penalties>
		<!-- 听证告知书 -->
		<hearing-notice v-if="isheadringNotice" :headringNoticeObj="headringNoticeObj" @submit="headringNoticeFun"></hearing-notice>
		<view v-show="saveUrl == false &&　isTranscript　== false && isObligation == false && saveUrl2 == false && isAdministrative == false  && isheadringNotice == false" class="flex bottom-meun">
			<Attachment @choose="chooseImage" mode="create" :canUploadFile="true" :uploadFileUrl="uploadFileUrl" :heaer="header" :showProcess="true" :attachmentList.sync="attachmentList" @uploadSuccess="uploadSuccess">
				<view class="center left">
					证据上传
				</view>
			</Attachment>
		</view>
		<view v-show="saveUrl == false &&　isTranscript　== false && isObligation == false && saveUrl2 == false && isAdministrative == false && isAdministrative3 == false && isheadringNotice == false" class="template-1v1">
			<view style="width: 300px; height: 225px;position: fixed;top: 0;right: 0;z-index: 99;"
				v-for="(item, index) in playerList" :key="item.streamID"
				v-if="item.src && (item.hasVideo || item.hasAudio)" class="view-container player-container"
				:class="item.isVisible?'':'none'">
				<live-player class="player" :id="item.streamID" :data-userid="item.userID"
					:data-streamid="item.streamID" :data-streamtype="item.streamType" :src="item.src" mode="RTC"
					:autoplay="true" :mute-audio="item.muteAudio" :mute-video="item.muteVideo"
					:orientation="item.orientation" :object-fit="item.objectFit"
					:background-mute="item.enableBackgroundMute" :min-cache="item.minCache" :max-cache="item.maxCache"
					:sound-mode="item.soundMode" :enable-recv-message="item.enableRecvMessage"
					:auto-pause-if-navigate="item.autoPauseIfNavigate"
					:auto-pause-if-open-native="item.autoPauseIfOpenNative" :debug="debug"
					@statechange="_playerStateChange" @fullscreenchange="_playerFullscreenChange"
					@netstatus="_playerNetStatus" @error="error" @audiovolumenotify="_playerAudioVolumeNotify">
				</live-player>
			</view>
			
			<view
				:class="'view-container pusher-container ' + (pusher.isVisible?'':'none') + ' ' + (playerList.length>0 ? 'fullscreen':'')">
				<live-pusher class="pusher" :url="pusher.url" :mode="pusher.mode" :autopush="pusher.autopush"
					:enable-camera="pusher.enableCamera" :enable-mic="pusher.enableMic" :muted="!pusher.enableMic"
					:enable-agc="pusher.enableAgc" :enable-ans="pusher.enableAns"
					:enable-ear-monitor="pusher.enableEarMonitor" :auto-focus="pusher.enableAutoFocus"
					:zoom="pusher.enableZoom" :min-bitrate="pusher.minBitrate" :max-bitrate="pusher.maxBitrate"
					:video-width="pusher.videoWidth" :video-height="pusher.videoHeight" :beauty="pusher.beautyLevel"
					:whiteness="pusher.whitenessLevel" :orientation="pusher.videoOrientation"
					:aspect="pusher.videoAspect" :device-position="pusher.frontCamera"
					:remote-mirror="pusher.enableRemoteMirror" :local-mirror="pusher.localMirror"
					:background-mute="pusher.enableBackgroundMute" :audio-quality="pusher.audioQuality"
					:audio-volume-type="pusher.audioVolumeType" :audio-reverb-type="pusher.audioReverbType"
					:waiting-image="pusher.waitingImage" :debug="debug" @statechange="_pusherStateChangeHandler"
					@netstatus="_pusherNetStatusHandler" @error="_pusherErrorHandler" @bgmstart="_pusherBGMStartHandler"
					@bgmprogress="_pusherBGMProgressHandler" @bgmcomplete="_pusherBGMCompleteHandler"
					@audiovolumenotify="_pusherAudioVolumeNotify"></live-pusher>
				<view class="loading" v-if="playerList.length === 0">
					<view class="loading-img">
						<image src="/static/image/loading.png" class="rotate-img"></image>
					</view>
					<view class="loading-text">等待大队连接...</view>
				</view>
				<transcript-view style="position: absolute !important;top: 0 !important;bottom: 0 !important;right: 0 !important;left: 0 !important;z-index: 9999 !important;width: 100vw;height: 100vh;" v-if="isTranscript" :transcriptList="transcriptList" @submit="submit"></transcript-view>
			</view>
			<view class="handle-btns">
<!-- 				<view class="btn-normal" @tap="_pusherAudioHandler">
					<image class="btn-image"
						:src="pusher.enableMic? '/static/static/images/audio-true.png': '/static/static/images/audio-false.png'">
					</image>
				</view>
				<view class="btn-normal" @tap="_pusherSwitchCamera">
					<image class="btn-image" src="/static/static/images/switch.png"></image>
				</view> -->
<!-- 				<view class="btn-normal" bindtap="_toggleVideo">
		      <image class="btn-image" src="{{pusher.enableCamera? './static/camera-true.png': './static/camera-false.png'}} "></image>
		    </view> -->
<!-- 				<view class="btn-normal" @tap="_setPlayerSoundMode">
					<image class="btn-image"
						:src="playerList[0].soundMode === 'ear' ? '/static/static/images/speaker-false.png': '/static/static/images/speaker-true.png'">
					</image>
				</view> -->
			</view>
			<view class="bottom-btns">
				<!-- 笑脸按钮 -->
<!-- 				<view class="btn-normal" data-key="beautyLevel" data-value="9|0" data-value-type="number"
					@tap="_setPusherBeautyHandle">
					<image class="btn-image"
						:src="pusher.beautyLevel == 9 ? '/static/static/images/beauty-true.png': '/static/static/images/beauty-false.png'">
					</image>
				</view>
				<view class="btn-hangup" @tap="_hangUp">
					<image class="btn-image" src="/static/static/images/hangup.png"></image>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	import {
		randomRoomID
	} from '../../utils/common.js'
	import TRTC from '../../static/trtc-wx.js'
	import Attachment from '@/components/jin-attachment/jin-attachment.vue';
	import permision from "@/common/permission.js"
	//签字
	import signView from '@/components/sign-view.vue'
	//笔录确认
	import transcriptView from "@/components/transcript-view.vue"
	//权力义务告知
	import obligationInform from "@/components/obligation-inform.vue"
	//行政处罚告知书 
	import administrativePenalties from '@/components/administrative-penalties.vue'
	import hearingNotice from '@/components/hearing-notice.vue'
	var sourceType = [
		['camera'],
		['album'],
		['camera', 'album']
	]
	var sizeType = [
		['compressed'],
		['original'],
		['compressed', 'original']
	]
	// -图片上传-
	export default {
		components: {
			Attachment,
			signView,
			transcriptView,
			obligationInform,
			administrativePenalties,
			hearingNotice
		},
		data() {
			return {
				windowHeight: 0,
				title: 'choose/previewImage',
				sourceTypeIndex: 2,
				sourceType: ['拍照', '相册', '拍照或相册'],
				sizeTypeIndex: 0,
				sizeType: ['压缩', '原图', '压缩或原图'],
				countIndex: 3,
				count: [1, 2, 3, 4, 5, 6],
				num: false,
				imageLists: [],
				uploadFileUrl: "https://enforce.redifinetd.com/enforce_remote/file/uploadFile", //文件地址
				header: {
					// 如果需要header，请上传
				},
				attachmentList: [], // 文件上传列表
				rtcConfig: {
					sdkAppID: '',
					// 必要参数 开通实时音视频服务创建应用后分配的 sdkAppID
					userID: '',
					// 必要参数 用户 ID 可以由您的帐号系统指定
					userSig: '' // 必要参数 身份签名，相当于登录密码的作用
				},
				pusher: null,
				playerList: [], // 拉流列表
				debug: false ,// 是否开启调试模式
				saveUrl: false,// 是否显示签字版
				saveUrl2: false, //笔录确认描边 
				biluUrl: "",
				isTranscript: false,// 笔录确认
				transcriptList: {} ,// 笔录信息
				inquiryRoomId: 0 ,// 询问室id
				brigadeId: 0 ,// 大队id
				phone: 0 ,//电话号码
				isObligation: false, //是否显示权力义务告知书
				isObligation2: false,
				obligationObj: null,
				isAdministrative: false, //行政处罚告知书显示
				isAdministrative2: false, //行政处罚告知书描边显示
				isAdministrative3: false, //行政处罚告知书签字显示
				administrativeObj: {},//行政处罚告知书内容,
				chufaUrl: '',//行政处罚告知书描边图片
				headringNoticeObj: null,//听证告知内容
				isheadringNotice: false,//听证告知书显示
				isheadringNotice2: false,
				isheadringNotice3: false,
				strokeUrl: ''//听证告知书描边图片
			}
		},
		onUnload() {
			this.sourceTypeIndex = 2,
			this.sourceType = ['拍照', '相册', '拍照或相册'],
			this.sizeTypeIndex = 2,
			this.sizeType = ['压缩', '原图', '压缩或原图'],
			this.countIndex = this.mostUploadImage;
			console.log('room unload');
			this.close()//关闭连接
		},
		onLoad(options){
			this.phone = options.phone
			this.inquiryRoomId = options.inquiryRoomId
			this.brigadeId = options.brigadeId
			
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight - 78
				}
			});
			console.log('room onload', options);
			uni.setKeepScreenOn({
				keepScreenOn: true
			});
			this.TRTC = new TRTC(this);
			this.init(options);
			this.bindTRTCRoomEvent();
			this.enterRoom({
				roomID: options.roomID
			});
			let URL = `wss://enforce.redifinetd.com/enforce_remote/wss/WebSocket/${options.brigadeId}/${options.phone}`
			//let URL = `ws://121.196.29.201:8103/WebSocket/1/188`
			this.connect(URL)
		},
		onReady() {
			console.log('room ready');
		},
		// 离开页面
		// onHide() {
		// 	this.exitRoom();
		// },
		methods: {
			
			bilu(url) {
				if (url) {
					this.biluUrl = url
					this.saveUrl2 = false
					this.saveUrl = true
				} else {
					uni.showToast({
						title: "生成失败，请重试",
						duration: 1000
					})
				}
			},
			//行政处罚告知书描边
			bilu2(url) {
				if (url) {
					this.chufaUrl = url
					this.isAdministrative2 = false
					this.isAdministrative3 = true
				} else {
					uni.showToast({
						title: "生成失败，请重试",
						duration: 1000
					})
				}
			},
			//行政处罚告知书签字
			save3(url) {
				const objUrl = {
					biluUrl: this.chufaUrl,
					messageUrl: url
				}
				const obj = {
				  toUserId: this.inquiryRoomId,
				  fromUserId: this.phone,
				  message: objUrl,
				  type: 0,
				  code: 6
				}
				const str = JSON.stringify(obj)
				this.socketTask.send({
					data: str,
					success(res) {
						console.log(res);
						console.log("消息发送成功")
					},
					fail(err) {
						console.log(err);
					}
				})
				this.isAdministrative3 = false
			},
			//听证告知书描边
			stroke(url) {
				if (url) {
					this.strokeUrl = url
					this.isheadringNotice2 = false
					this.isheadringNotice3 = true
				} else {
					uni.showToast({
						title: "生成失败，请重试",
						duration: 1000
					})
				}
			},
			//听证告知书签字
			hearingsign(url) {
				const objUrl = {
					biluUrl: this.strokeUrl,
					messageUrl: url
				}
				const obj = {
				  toUserId: this.inquiryRoomId,
				  fromUserId: this.phone,
				  message: objUrl,
				  type: 0,
				  code: 7
				}
				const str = JSON.stringify(obj)
				this.socketTask.send({
					data: str,
					success(res) {
						console.log(res);
						console.log("消息发送成功")
					},
					fail(err) {
						console.log(err);
					}
				})
				this.isheadringNotice3 = false
			},
			// 签字确认
			save(url) {
				const objUrl = {
					biluUrl: this.biluUrl,
					messageUrl: url
				}
				const obj = {
				  toUserId: this.inquiryRoomId,
				  fromUserId: this.phone,
				  message: objUrl,
				  type: 0,
				  code: 3
				}
				const str = JSON.stringify(obj)
				this.socketTask.send({
					data: str,
					success(res) {
						console.log(res);
						console.log("消息发送成功")
					},
					fail(err) {
						console.log(err);
					}
				})
				this.saveUrl = false
			},
			save2(url) {
				let obj = {
				  toUserId: this.inquiryRoomId,
				  fromUserId: this.phone,
				  message: url,
				  type: 0,
				  code: 4
				}
				let str = JSON.stringify(obj)
				let that = this
				this.socketTask.send({
					data: str,
					success:(res)=> {
						console.log(res);
						console.log("消息发送成功")
						that.isObligation = false
						that.isObligation2 = false
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			// 笔录确认
			submit() {
				let obj = {
				  toUserId: this.inquiryRoomId,
				  fromUserId: this.phone,
				  message: "笔录确认",
				  type: 0,
				  code: 2
				}
				let str = JSON.stringify(obj)
				let that = this
				this.socketTask.send({
					data: str,
					success:(res)=> {
						console.log(res);
						console.log("消息发送成功")
						that.isTranscript = false
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			//权利义务告知确认
			obligationFun() {
				this.isObligation2 = true
			},
			//行政处罚告知书确认
			administrativeFun() {
				this.isAdministrative = false
				this.isAdministrative2 = true
			},
			//听证告知书
			headringNoticeFun() {
				this.isheadringNotice = false
				this.isheadringNotice2 = true
			},
			//以下websocket
			connect(url) {
				let that = this
				this.socketTask = uni.connectSocket({
					url: url,
					success(res) {
						console.log("连接成功")
						console.log(res)
					},
					fail(err) {
						console.log(err)
					}
				})
				this.socketTask.onOpen((res) => {
					console.log('onOpen')
					console.log(res)
				})
				this.socketTask.onError((err) => {
					console.log('onError')
					console.log(err)
				})
				this.socketTask.onMessage((res) => {
					console.log("收到消息")
					let obj = JSON.parse(res.data)
					console.log(obj)
					// 笔录确认
					if (obj.code == 2) {
						console.log("笔录确认了")
						this.isTranscript = true
						this.transcriptList = obj.message
						console.log(obj.message)
						console.log(this.isTranscript)
					}
					// 签字确认
					if (obj.code == 3) {
						console.log("签字确认了")
						this.saveUrl2 = true
						console.log(this.saveUrl)
					}
					// 权力义务告知确认
					if (obj.code == 4) {
						console.log("权力义务告知确认")
						this.obligationObj = obj.message
						this.isObligation = true
						console.log('权力义务告知书', this.isObligation)
					}
					// 行政处罚告知书
					if (obj.code == 6) {
						this.administrativeObj = obj.message
						this.isAdministrative = true
						console.log('行政处罚告知书', this.administrativeObj)
					}
					// 听证告知书
					if (obj.code == 7) {
						console.log("行政处罚告知书确认")
						this.headringNoticeObj = obj.message
						this.isheadringNotice = true
						console.log('行政处罚告知书', this.headringNoticeObj)
					}
					// 挂断退出房间
					if (obj.code == 10) {
						this.exitRoom();
						// 关闭所有页面打开信息录入页面
						uni.showToast({
							title: '远程询问结束',
							duration: 800
						})
						setTimeout(()=> {
							uni.reLaunch({
								url: './evidence-upload?end=1'
							})
						},800)
					}
				})
				this.socketTask.onClose((res) => {
					console.log('onClose', res)
					console.log('连接已关闭')
				})
				console.log('task', this.socketTask)
			},
			//发送消息
			send(map) {
				this.socketTask.send({
					data: JSON.stringify(map),
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			//关闭连接
			close() {
				if (this.socketTask && this.socketTask.close) {
					this.socketTask.close()
				}
			},
			error(e) {
				console.error('live-player error:', e.detail.errMsg)
			},
			init(options) {
				// pusher 初始化参数
				const pusherConfig = {
					beautyLevel: 9
				};
				const pusher = this.TRTC.createPusher(pusherConfig);
				console.log(pusher.pusherAttributes, '000');
				this.rtcConfig = {
					userID: options.userID,
					sdkAppID: options.sdkAppID,
					userSig: options.userSig
				}
				this.pusher = pusher.pusherAttributes
			},

			enterRoom(options) {
				const roomID = options.roomID || randomRoomID();
				console.log("进房--->roomId = "+roomID)
				const config = Object.assign(this.rtcConfig, {
					roomID
				});
				this.pusher = this.TRTC.enterRoom(config)
				this.TRTC.getPusherInstance().start(); // 开始推流（autoPush的模式下不需要）
			},

			exitRoom() {
				const result = this.TRTC.exitRoom();
				this.pusher = result.pusher,
				this.playerList = result.playerList
			},

			// 设置 pusher 属性
			setPusherAttributesHandler(options) {
				this.pusher = this.TRTC.setPusherAttributes(options)
			},

			// 设置某个 player 属性
			setPlayerAttributesHandler(player, options) {
				this.playerList = this.TRTC.setPlayerAttributes(player.streamID, options)
				console.log(222)
				console.log('playerList:',this.playerList)
				console.log(333)
			},

			// 事件监听
			bindTRTCRoomEvent() {
				const TRTC_EVENT = this.TRTC.EVENT; // 初始化事件订阅
				console.log("初始化事件订阅:"+TRTC_EVENT)

				this.TRTC.on(TRTC_EVENT.LOCAL_JOIN, event => {
					console.log('* room LOCAL_JOIN', event); // // 进房成功，触发该事件后可以对本地视频和音频进行设置

					this.setPusherAttributesHandler({
						enableCamera: true
					});
					this.setPusherAttributesHandler({
						enableMic: true
					});
				});
				this.TRTC.on(TRTC_EVENT.LOCAL_LEAVE, event => {
					console.log('* room LOCAL_LEAVE', event);
				});
				this.TRTC.on(TRTC_EVENT.ERROR, event => {
					console.log('* room ERROR', event);
				});

				// 远端用户退出	
				this.TRTC.on(TRTC_EVENT.REMOTE_USER_LEAVE, event => {
					const {
						playerList
					} = event.data;
					this.playerList = playerList
					console.log('* room REMOTE_USER_LEAVE', event);
				});

				// 远端用户推送视频
				this.TRTC.on(TRTC_EVENT.REMOTE_VIDEO_ADD, event => {
					console.log('* room REMOTE_VIDEO_ADD', event);
					const {
						player
					} = event.data; // 开始播放远端的视频流，默认是不播放的
					this.setPlayerAttributesHandler(player, {
						muteVideo: false
					})
				}); // 远端用户取消推送视频

				this.TRTC.on(TRTC_EVENT.REMOTE_VIDEO_REMOVE, event => {
					console.log('* room REMOTE_VIDEO_REMOVE', event);
					const {
						player
					} = event.data;
					this.setPlayerAttributesHandler(player, {
						muteVideo: true
					});
				}); // 远端用户推送音频

				this.TRTC.on(TRTC_EVENT.REMOTE_AUDIO_ADD, event => {
					console.log('* room REMOTE_AUDIO_ADD', event);
					const {
						player
					} = event.data;
					this.setPlayerAttributesHandler(player, {
						muteAudio: false
					});
				}); // 远端用户取消推送音频

				this.TRTC.on(TRTC_EVENT.REMOTE_AUDIO_REMOVE, event => {
					console.log('* room REMOTE_AUDIO_REMOVE', event);
					const {
						player
					} = event.data;
					this.setPlayerAttributesHandler(player, {
						muteAudio: true
					});
				});
			},

			// 是否订阅某一个player Audio
			_mutePlayerAudio(event) {
				const player = event.currentTarget.dataset.value;

				if (player.hasAudio && player.muteAudio) {
					this.setPlayerAttributesHandler(player, {
						muteAudio: false
					});
					return;
				}

				if (player.hasAudio && !player.muteAudio) {
					this.setPlayerAttributesHandler(player, {
						muteAudio: true
					});
					return;
				}
			},

			// 订阅 / 取消订阅某一个player Video
			_mutePlayerVideo(event) {
				const player = event.currentTarget.dataset.value;

				if (player.hasVideo && player.muteVideo) {
					this.setPlayerAttributesHandler(player, {
						muteVideo: false
					});
					return;
				}

				if (player.hasVideo && !player.muteVideo) {
					this.setPlayerAttributesHandler(player, {
						muteVideo: true
					});
					return;
				}
			},

			// 挂断退出房间
			_hangUp() {
				this.exitRoom();
				uni.navigateBack({
					delta: 1
				});
			},

			// 设置美颜
			_setPusherBeautyHandle() {
				const beautyLevel = this.pusher.beautyLevel === 0 ? 9 : 0;
				this.setPusherAttributesHandler({
					beautyLevel
				});
			},

			// 发布 / 取消发布 Audio
			_pusherAudioHandler() {
				if (this.pusher.enableMic) {
					this.setPusherAttributesHandler({
						enableMic: false
					});
				} else {
					this.setPusherAttributesHandler({
						enableMic: true
					});
				}
			},

			_pusherSwitchCamera() {
				const frontCamera = this.pusher.frontCamera === 'front' ? 'back' : 'front';
				this.TRTC.getPusherInstance().switchCamera(frontCamera);
			},

			_setPlayerSoundMode() {
				if (this.playerList.length === 0) {
					return;
				}

				const player = this.TRTC.getPlayerList();
				const soundMode = player[0].soundMode === 'speaker' ? 'ear' : 'speaker';
				this.setPlayerAttributesHandler(player[0], {
					soundMode
				});
			},

			// 请保持跟 wxml 中绑定的事件名称一致
			_pusherStateChangeHandler(event) {
				this.TRTC.pusherEventHandler(event);
			},

			_pusherNetStatusHandler(event) {
				this.TRTC.pusherNetStatusHandler(event);
			},

			_pusherErrorHandler(event) {
				this.TRTC.pusherErrorHandler(event);
			},

			_pusherBGMStartHandler(event) {
				this.TRTC.pusherBGMStartHandler(event);
			},

			_pusherBGMProgressHandler(event) {
				this.TRTC.pusherBGMProgressHandler(event);
			},

			_pusherBGMCompleteHandler(event) {
				this.TRTC.pusherBGMCompleteHandler(event);
			},

			_pusherAudioVolumeNotify(event) {
				this.TRTC.pusherAudioVolumeNotify(event);
			},

			_playerStateChange(event) {
				this.TRTC.playerEventHandler(event);
			},

			_playerFullscreenChange(event) {
				this.TRTC.playerFullscreenChange(event);
			},

			_playerNetStatus(event) {
				this.TRTC.playerNetStatus(event);
			},

			_playerAudioVolumeNotify(event) {
				this.TRTC.playerAudioVolumeNotify(event);
			},
			signFun() {
				this.saveUrl = true
			},
			record() {
				this.isTranscript = true
			},
			// 文件上传
			uploadSuccess(result) {
				if (result.statusCode == 200) {
					//上传成功的回调处理
					const obj = JSON.parse(result.data)
					console.log(obj)
					if (obj.code == "S000") {
						let data = {
						  toUserId: this.inquiryRoomId,
						  fromUserId: this.phone,
						  message: obj.data,
						  type: 0,
						  code: 5
						}
						let str = JSON.stringify(data)
						let that = this
						this.socketTask.send({
							data: str,
							success(res) {
								console.log(res);
								console.log("消息发送成功")
								that.isTranscript = false
							},
							fail(err) {
								console.log(err);
							}
						})
					}
				} else {
					uni.showToast({
						title: '上传失败',
						icon: 'none'
					});
				}
			},
			// 图片上传
			chooseImage: async function() {
				// #ifdef APP-PLUS
				// TODO 选择相机或相册时 需要弹出actionsheet，目前无法获得是相机还是相册，在失败回调中处理
				if (this.sourceTypeIndex !== 2) {
					let status = await this.checkPermission();
					if (status !== 1) {
						return;
					}
				}
				// #endif
				uni.chooseImage({
					sourceType: sourceType[this.sourceTypeIndex],
					sizeType: sizeType[this.sizeTypeIndex],
					count: this.mostUploadImage,
					success: (res) => {
						// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
						var tempFilePaths = res.tempFilePaths;
						//支持多图上传
						for (var i = 0; i < tempFilePaths.length; i++) {
							wx.uploadFile({
								url: `${request.commonUrl}/file/uploadFile`, //仅为示例，非真实的接口地址
								filePath: tempFilePaths[0],
								name: 'file',
								formData: {
									'type': 0
								},
								success: (res) => {
									let resData = JSON.parse(res.data)
									console.log(resData.code)
									if (resData.code === "S000") {
										console.log(resData.data)
										let data = {
										  toUserId: this.inquiryRoomId,
										  fromUserId: this.phone,
										  message: resData.data,
										  type: 0,
										  code: 5
										}
										let str = JSON.stringify(data)
										let that = this
										this.socketTask.send({
											data: str,
											success(res) {
												console.log(res);
												console.log("消息发送成功")
												that.isTranscript = false
											},
											fail(err) {
												console.log(err);
											}
										})
									}
								}
							})
						}
					},
					fail: (err) => {
						console.log(err)
						// #ifdef APP-PLUS
						if (err['code'] && err.code !== 0 && this.sourceTypeIndex === 2) {
							this.checkPermission(err.code);
						}
						// #endif
						// #ifdef MP
						uni.getSetting({
							success: (res) => {
								let authStatus = false;
								switch (this.sourceTypeIndex) {
									case 0:
										authStatus = res.authSetting['scope.camera'];
										break;
									case 1:
										authStatus = res.authSetting['scope.album'];
										break;
									case 2:
										authStatus = res.authSetting['scope.album'] && res
											.authSetting['scope.camera'];
										break;
									default:
										break;
								}
							}
						})
						// #endif
					}
				})
			},
			async checkPermission(code) {
				let type = code ? code - 1 : this.sourceTypeIndex;
				let status = permision.isIOS ? await permision.requestIOS(sourceType[type][0]) :
					await permision.requestAndroid(type === 0 ? 'android.permission.CAMERA' :
						'android.permission.READ_EXTERNAL_STORAGE');

				if (status === null || status === 1) {
					status = 1;
				} else {
					uni.showModal({
						content: "没有开启权限",
						confirmText: "设置",
						success: function(res) {
							if (res.confirm) {
								permision.gotoAppSetting();
							}
						}
					})
				}
				return status;
			}
		}
	}
</script>

<style scoped lang="scss">
	/* 1v1 视频电话模式 */
	.template-1v1 {
		width: 100%;
		height: 100%;
		position: relative;
	}

	.template-1v1 .pusher-container {
		width: 240rpx;
		height: 320rpx;
		position: absolute;
		right: 20rpx;
		top: 0;
		z-index: 2;
	}

	.pusher {
		height: 100%;
	}

	.player {
		height: 100%;
		width: 100%;
	}

	.template-1v1 .pusher-container.fullscreen {
		width: 100vw;
		height: 95vh;
		top: 0;
		right: 0;
	}

	.template-1v1 .loading {
		position: absolute;
		top: 40vh;
		left: 50vw;
		transform: translate(-50%, 0);
		width: 300rpx;
		height: 250rpx;
		border-radius: 12rpx;
		background: rgba(0, 0, 0, 0.6);
		color: white;
		padding: 40rpx;
		display: flex;
		flex-direction: column;
	}

	.template-1v1 .loading-img {
		height: 200rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		animation: rotate 2s linear infinite;
	}

	.template-1v1 .rotate-img {
		width: 160rpx;
		height: 160rpx;
	}

	.template-1v1 .loading-text {
		width: 100%;
		padding-top: 40rpx;
		text-align: center;
	}

	@keyframes rotate {
		0% {
			transform: rotate(0deg);
		}

		50% {
			transform: rotate(180deg);
		}

		100% {
			transform: rotate(360deg);
		}
	}

	.template-1v1 .player-container:nth-child(1) {
		width: 100vw;
		height: 100vh;
	}

	.template-1v1 .handle-btns {
		position: absolute;
		z-index: 3;
		bottom: 15vh;
		width: 100vw;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}

	.template-1v1 .bottom-btns {
		position: absolute;
		z-index: 3;
		bottom: 3vh;
		width: 100vw;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}

	/* .template-1v1 image {
	  width: 4vh;
	  height: 4vh;
	} */

	.template-1v1 .btn-normal {
		width: 8vh;
		height: 8vh;
		box-sizing: border-box;
		display: flex;
		background: white;
		justify-content: center;
		align-items: center;
		border-radius: 50%;
	}

	.template-1v1 .btn-hangup .btn-image,
	.template-1v1 .btn-normal .btn-image {
		width: 4vh;
		height: 4vh;
	}

	.template-1v1 .btn-hangup {
		width: 8vh;
		height: 8vh;
		background: #f75c45;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 50%;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		position: fixed;
		top: 0;
		right: 0;
	}

	.bottom-meun {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 9999;
		background: #808080;
		// justify-content: space-around;

		view {
			width: 184rpx;
			height: 5vh;
			background: #FFA734;
			border-radius: 4rpx;
			font-weight: 500;
			color: #FFFFFF;
		}

		.left {
			background-color: #FFA734;
		}

		.cen {
			background-color: #11A144;
		}

		.right {
			background-color: #3961FA;
		}
	}
	
	.bottom-meun2 {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 9999;
		justify-content: space-around;
		width: 500rpx;
		height: 500rpx;
		// background: #007AFF;
	
		view {
			width: 184rpx;
			height: 80rpx;
			background: #FFA734;
			border-radius: 4rpx;
			font-weight: 500;
			color: #FFFFFF;
		}
	
		.left {
			background-color: #FFA734;
		}
	
		.cen {
			background-color: #11A144;
		}
	
		.right {
			background-color: #3961FA;
		}
	}
	
	.divcss5-x10 {
		// padding-bottom: 20rpx;
		// border-bottom: 1px solid #E6E6E6;
		display: inline;
		color: #333333;
		font-size: 28rpx;
		line-height: 60rpx;
		white-space: pre-wrap;
		width: 100%;
		padding-top: 10rpx;
	}

	.divcss5-x1 {
		// padding-bottom: 20rpx;
		// border-bottom: 1px solid #E6E6E6;
		display: inline;
		color: #333333;
		font-size: 28rpx;
		line-height: 60rpx;
		white-space: pre-wrap;
		width: 100%;
		padding-top: 10rpx;
	}

	.linediv {
		position: absolute;
		border-bottom: 1rpx solid #E6E6E6;
		height: 1rpx;
		background: #E6E6E6;
		bottom: 1rpx;
		left: 0;
		right: 0;
		width: 99%;
	}
	
	
	.signa {
		position: relative;
		overflow: hidden;
		background-color: #fbfbfb;
		height: 100vh;
		width: 100vw;
	
		.canvas {
			background-color: #FFFFFF;
			position: absolute;
			z-index: 9999;
			left: 45px;
		}
	
		.btn {
			height: 100vh;
			position: fixed;
			background-color: #007AFF;
			font-size: 30rpx;
	
			.cancel-btn {
				width: 42vh;
				position: fixed;
				left: 50rpx;
				border: 1px solid #AAAAAA;
				transform: rotate(90deg);
				color: #3961FA;
				margin-left: -21vh;
				margin-top: 21vh;
				height: 63rpx;
				line-height: 65rpx;
				border-radius: 3px;
				text-align: center;
				justify-content: center;
				background: #FFFFFF;
			}
	
			.save-btn {
				position: absolute;
				z-index: 999;
				display: inline-flex;
				margin-top: 67vh;
				margin-left: -21vh;
				transform: rotate(90deg);
				background: #3961FA;
				width: 42vh;
				left: 50rpx;
				border-radius: 3px;
				color: #fff;
				height: 65rpx;
				line-height: 65rpx;
				text-align: center;
				justify-content: center;
			}
		}
	}
	
	.inform-position {
		position: fixed !important;
		top: 0 !important;
		bottom: 0 !important;
		right: 0 !important;
		left: 0 !important;
		z-index: 99;
	}
</style>
<style>
	page {
		/* background: red; */
	}
	scroll-view ::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
		display: none;
	}
</style>